<template>
  <div class="notice">
    <waterfall :col="1" :data="noticeList" @loadmore="loadmore" class="water">
      <div
        class="box"
        v-for="item in noticeList"
        :key="item.id"
        @click="goDetails(item.id)"
      >
        <div class="boxImg"><img :src="item.url" alt="" /></div>
        <div class="boxText">
          <p class="p1">{{ item.title }}</p>
          <p class="p2">{{ item.sub_title }}</p>
          <p class="p1 p3">{{ item.tags }}</p>
        </div>
      </div>
    </waterfall>
    <!-- </van-list> -->
    <div v-if="showFlag" class="noMore">没有更多了</div>
  </div>
</template>

<script>
import Vue from "vue";
import { List } from "vant";
import waterfall from "vue-waterfall2";
Vue.use(waterfall);
Vue.use(List);
import apiMar from "@/api/api";
export default {
  components: {},
  data() {
    return {
      pageData: {
        total: 0,
        current: 1,
        pageSize: 10
      },
      noticeList: [],
      loading: false,
      finished: false,

      total: "",
      showFlag: false
    };
  },
  computed: {},
  watch: {},
  methods: {
    getData() {
      let params = {
        current: this.pageData.current,
        pageSize: this.pageData.pageSize
      };
      apiMar
        .getNotice(params)
        .then(res => {
          this.total = res.total;
          this.noticeList = this.noticeList.concat(res.data);
          this.noticeList.forEach(item => {
            item.url = item.image.url;
          });

          if (this.total == this.noticeList.length) {
            this.showFlag = true;
          }
        })
        .catch(err => {
          // this.$Message.error(err)
        });
    },
    loadmore(val) {
      console.log("loadmore");
      // console.log(val, 'loadmoreloadmoreloadmoreloadmoreloadmoreloadmore');
      if (this.total != this.noticeList.length) {
        this.pageData.current = this.pageData.current + 1;
        console.log(this.pageData.current, "valvalvlavlv");
        this.getData();
      }
    },

    goDetails(val) {
      this.$router.push({
        path: "/noticeDetails",
        query: {
          id: val
        }
      });
    }
  },
  created() {
    this.getData();
  },
  mounted() {}
};
</script>
<style lang="scss" scoped>
.water {
  padding-bottom: 10px;
}
.notice {
  padding-bottom: 100px;

  .noMore {
    text-align: center;
    font-size: 14px;
    color: #999;
    padding: 30px 0;
  }
}

.box {
  box-sizing: border-box;
  width: 90%;
  margin: 15px auto 0;
  background-color: rgba(255, 255, 255, 1);
  box-shadow: 0px 2px 8px rgba(0, 0, 0, 0.05);
  border-radius: 12px;
  padding: 16px;
  display: flex;
  flex-direction: row;

  .boxImg {
    width: 72px;
    height: 90px;

    img {
      display: block;
      width: 100%;
      height: 100%;
      border-radius: 10px;
    }
  }

  .boxText {
    flex: 1;
    padding-left: 16px;

    p {
      margin-top: 8px;
      line-height: 1.4;
    }

    p.p1 {
      font-size: 14px;
      color: rgba(136, 148, 162, 1);
    }

    p.p2 {
      font-size: 16px;
      color: rgba(38, 38, 46, 1);
      text-overflow: -o-ellipsis-lastline;
      overflow: hidden;
      text-overflow: ellipsis;
      display: -webkit-box;
      -webkit-line-clamp: 2;
      line-clamp: 2;
      -webkit-box-orient: vertical;
    }
  }
}
</style>
